﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SD.IBUS;
using SD.IDAL;
using SD.Entities;
using SD.DAL;
using System.Data;
using System.Data.SqlClient;

namespace SD.BUS
{
    public class ProgrammeBIZ : BaseBIZ, IProgrammeBIZ
    {
        IProgrammeDAO iProDAO;
        
        /// <summary>
        /// Constructor of programmebiz
        /// </summary>
        public ProgrammeBIZ()
        {
            iProDAO = new ProgrammeDAO();
        }

        /// <summary>
        /// Get all Programme by includeInactive
        /// </summary>
        /// <param name="includeInactive"></param>
        /// <returns>DataTable</returns>
        public DataTable GetAll(Boolean includeInactive)
        {
            DataTable dtResult = new DataTable();
            dtResult.Columns.Add("ProgrammeId");
            dtResult.Columns.Add("Name");

            List<Programme> list = new List<Programme>();
            list = iProDAO.GetAll(includeInactive);
            //If rows of list >0
            if (list.Count > 0)
            {
                //Get Programme from list Programme 
                foreach (Programme pro in list)
                {
                    dtResult.Rows.Add(pro.ProgrammeId, pro.Name);
                }
            }

            return dtResult;
        }

        /// <summary>
        /// Get programme by id
        /// </summary>
        /// <param name="serviceId">ID of the programme</param>
        /// <returns>Found programme</returns>
        public Programme GetById(String programmeId)
        {
            try
            {
                return iProDAO.GetById(programmeId);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
    }
}
